package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.BookingsInfoAddDTO;
import org.jsola.hr.dto.BookingsInfoUpdateDTO;
import org.jsola.hr.entity.BookingsInfoDO;
import org.jsola.hr.query.BookingsInfoQuery;
import org.jsola.hr.service.IBookingsInfoService;
import org.jsola.hr.vo.BookingsInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 预约业务人员信息表
 *
 * @author zhr
 */
@Component
public class BookingsInfoTestHelper extends BaseTestHelper {
    
    @Autowired
    private IBookingsInfoService bookingsInfoService;

    /**
     * 生成add测试数据
     * @return BookingsInfoAddDTO
     */
    public BookingsInfoAddDTO getBookingsInfoAddDTO(){
        BookingsInfoAddDTO bookingsInfoAddDTO = new BookingsInfoAddDTO();
        bookingsInfoAddDTO.setName(getRandomValue("varchar",50));
        bookingsInfoAddDTO.setPhone(getRandomValue("varchar",11));
        bookingsInfoAddDTO.setUserId(getRandomValue("varchar",32));
        bookingsInfoAddDTO.setBookingsBusiness(getRandomValue("varchar",50));
        bookingsInfoAddDTO.setServiceFall(getRandomValue("varchar",50));
        bookingsInfoAddDTO.setBookingsDay((Date)ClassKit.getObjectValue(getRandomValue("date",0),"java.util.Date"));
        bookingsInfoAddDTO.setBookingsDatetime(getRandomValue("varchar",50));
        bookingsInfoAddDTO.setBookingsDatetimeId(SafeKit.getLong(getRandomValue("bigint",11)));
        bookingsInfoAddDTO.setBusinessId(SafeKit.getLong(getRandomValue("bigint",11)));
        return bookingsInfoAddDTO;
    }


    /**
     * 生成update测试数据
     * @return BookingsInfoUpdateDTO
     */
    public BookingsInfoUpdateDTO getBookingsInfoUpdateDTO(BookingsInfoVO bookingsInfoVO){
        return bookingsInfoService.selectDOById(bookingsInfoVO.getId(), SITE_ID).to(BookingsInfoUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return BookingsInfoQuery
     */
    public BookingsInfoQuery getBookingsInfoQuery() {
        BookingsInfoQuery bookingsInfoQuery = new BookingsInfoQuery();
        List<BookingsInfoDO> bookingsInfoDOList = bookingsInfoService.list(new BookingsInfoDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(bookingsInfoDOList)) {
            BookingsInfoDO bookingsInfoDO = bookingsInfoDOList.get(0);
            bookingsInfoQuery = bookingsInfoDO.to(BookingsInfoQuery.class);
        }
        return bookingsInfoQuery;
    }

    /**
     * 保存示例
     * @return BookingsInfoVO
     */
    public BookingsInfoVO saveBookingsInfoExample(){
        BookingsInfoAddDTO addDTO = this.getBookingsInfoAddDTO();
        BookingsInfoVO bookingsInfoVO = bookingsInfoService.save(addDTO,buildTokenUser());
        return bookingsInfoVO;
    }


}

